﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using Xceed.Wpf.Toolkit.PropertyGrid;
using Xceed.Wpf.Toolkit.PropertyGrid.Editors;
using BOL.Models.Genome;

namespace BOL.Apps.GeneNetworkBrowser.Controls
{
    public partial class ChromosomeEditor : UserControl, ITypeEditor
    {
        #region Public properties

        //public static readonly DependencyProperty OrganismTypeProperty =
        //    DependencyProperty.Register("OrganismType", typeof(OrganismType), typeof(ChromosomeEditor),
        //    new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));

        public static readonly DependencyProperty ChromosomeNameProperty =
            DependencyProperty.Register("ChromosomeName", typeof(string), typeof(ChromosomeEditor),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));

        public static readonly DependencyProperty ChromosomeTypeProperty =
            DependencyProperty.Register("ChromosomeType", typeof(ChromosomeType), typeof(ChromosomeEditor),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));

        //public OrganismType OrganismType { get { return (OrganismType)GetValue(OrganismTypeProperty); } set { SetValue(OrganismTypeProperty, value); } }

        public string ChromosomeName { get { return (string)GetValue(ChromosomeNameProperty); } set { SetValue(ChromosomeNameProperty, value); } }

        public ChromosomeType ChromosomeType { get { return (ChromosomeType)GetValue(ChromosomeTypeProperty); } set { SetValue(ChromosomeTypeProperty, value); } }

        #endregion

        #region Constructor

        public ChromosomeEditor()
        {
            InitializeComponent();
        }

        #endregion

        #region Public methods

        public FrameworkElement ResolveEditor(PropertyItem propertyItem)
        {
            Binding binding = new Binding("OrganismType");
            //binding.Source = propertyItem;
            //binding.Mode = propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay;
            //BindingOperations.SetBinding(this, ChromosomeEditor.OrganismTypeProperty, binding);

            binding = new Binding("ChromosomeName")
                {Source = propertyItem, Mode = propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay};
            BindingOperations.SetBinding(this, ChromosomeEditor.ChromosomeNameProperty, binding);

            binding = new Binding("ChromosomeType")
                {Source = propertyItem, Mode = propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay};
            BindingOperations.SetBinding(this, ChromosomeEditor.ChromosomeTypeProperty, binding);

            return this;
        }

        #endregion
    }
}
